package com.jhgsys.internal.base.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.base.entity.HazardExamineUser;
import com.jhgsys.internal.base.service.IHazardExamineUserService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 *  Controller
 *
 * @author admin
 * @date 2024-09-04 13:23:28
 */
@Slf4j
@Validated
@Controller
public class HazardExamineUserController extends BaseController {

    @Autowired
    private IHazardExamineUserService hazardExamineUserService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineUser")
    @RequiresPermissions("hazardExamineUser:view")
    public String hazardExamineUserIndex(){
        return FebsUtil.view("base/hazardExamineUser/hazardExamineUserList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineUser/add")
    @RequiresPermissions("hazardExamineUser:add")
    public String hazardExamineUserAdd(){
        return FebsUtil.view("base/hazardExamineUser/hazardExamineUserEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineUser/update/{id}")
    @RequiresPermissions("hazardExamineUser:edit")
    public String hazardExamineUserUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("hazardExamineUser", hazardExamineUserService.findHazardExamineUserById(id));
        return FebsUtil.view("base/hazardExamineUser/hazardExamineUserEdit");
    }

    /**
     * 查询（所有）
     * @author admin
     * @date 2024-09-04 13:23:28
     */
    @GetMapping("hazardExamineUser")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:view")
    public FebsResponse getAllHazardExamineUsers(HazardExamineUser hazardExamineUser) {
        return new FebsResponse().success().data(hazardExamineUserService.findHazardExamineUserList(hazardExamineUser));
    }

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-09-04 13:23:28
     */
    @GetMapping("hazardExamineUser/list")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:view")
    public FebsResponse hazardExamineUserList(QueryRequest request, HazardExamineUser hazardExamineUser) {
        Map<String, Object> dataTable = getDataTable(this.hazardExamineUserService.findHazardExamineUserPage(request, hazardExamineUser));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 HazardExamineUser
     * @author admin
     * @date 2024-09-04 13:23:28
     */
    @Log("新增HazardExamineUser")
    @PostMapping("hazardExamineUser")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:add")
    public FebsResponse addHazardExamineUser(@Valid HazardExamineUser hazardExamineUser) throws FebsException {
        try {
            hazardExamineUser.setCreatedBy(getCurrentUser().getUserName());
            this.hazardExamineUserService.createHazardExamineUser(hazardExamineUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增HazardExamineUser失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
     * 逻辑删除 HazardExamineUser
     * @author admin
     * @date 2024-09-04 13:23:28
     */
    @Log("逻辑删除HazardExamineUser")
    @GetMapping("hazardExamineUser/delete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:delete")
    public FebsResponse deleteHazardExamineUser(@PathVariable("id") String hazardExamineUserIds) throws FebsException {
        try {
            HazardExamineUser hazardExamineUser = new HazardExamineUser();
            hazardExamineUser.setDeletedBy(getCurrentUser().getUserName());
            hazardExamineUser.setDeletedTime(new Date());
            hazardExamineUser.setDeletedFlg(FebsConstant.INVALID);
            this.hazardExamineUserService.deleteHazardExamineUser(hazardExamineUser,hazardExamineUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除HazardExamineUser失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
    * 物理删除 HazardExamineUser
    * @author admin
    * @date 2024-09-04 13:23:28
    */
    @Log("物理删除HazardExamineUser")
    @GetMapping("hazardExamineUser/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:delete")
    public FebsResponse physicallyDeleteHazardExamineUser(@PathVariable("id") String hazardExamineUserIds) throws FebsException {
        try {
            this.hazardExamineUserService.physicallyDeleteHazardExamineUser(hazardExamineUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除HazardExamineUser失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
     * 修改 HazardExamineUser
     * @author admin
     * @date 2024-09-04 13:23:28
     */
    @Log("修改HazardExamineUser")
    @PostMapping("hazardExamineUser/update")
    @ResponseBody
    @RequiresPermissions("hazardExamineUser:edit")
    public FebsResponse updateHazardExamineUser(HazardExamineUser hazardExamineUser) throws FebsException {
        try {
            hazardExamineUser.setUpdatedBy(getCurrentUser().getUserName());
            this.hazardExamineUserService.updateHazardExamineUser(hazardExamineUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改HazardExamineUser失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

}
